from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-11-28 14:03:30.468455
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 28, Nov, 2021
Time: 14:03:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2655
Nobs: 489.000 HQIC: -47.7340
Log likelihood: 5590.32 FPE: 1.37335e-21
AIC: -48.0371 Det(Omega_mle): 1.14461e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389917 0.083850 4.650 0.000
L1.Burgenland 0.094756 0.044726 2.119 0.034
L1.Kärnten -0.115946 0.022921 -5.058 0.000
L1.Niederösterreich 0.159971 0.093105 1.718 0.086
L1.Oberösterreich 0.121946 0.094529 1.290 0.197
L1.Salzburg 0.281609 0.047954 5.872 0.000
L1.Steiermark 0.020479 0.062140 0.330 0.742
L1.Tirol 0.107869 0.049980 2.158 0.031
L1.Vorarlberg -0.084171 0.044037 -1.911 0.056
L1.Wien 0.031007 0.084140 0.369 0.712
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.021290 0.186363 0.114 0.909
L1.Burgenland -0.051509 0.099408 -0.518 0.604
L1.Kärnten 0.036349 0.050945 0.714 0.476
L1.Niederösterreich -0.211142 0.206934 -1.020 0.308
L1.Oberösterreich 0.475986 0.210100 2.266 0.023
L1.Salzburg 0.310706 0.106582 2.915 0.004
L1.Steiermark 0.096280 0.138112 0.697 0.486
L1.Tirol 0.308450 0.111086 2.777 0.005
L1.Vorarlberg 0.008127 0.097877 0.083 0.934
L1.Wien 0.016209 0.187008 0.087 0.931
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238814 0.042603 5.606 0.000
L1.Burgenland 0.092890 0.022725 4.088 0.000
L1.Kärnten -0.004317 0.011646 -0.371 0.711
L1.Niederösterreich 0.217100 0.047305 4.589 0.000
L1.Oberösterreich 0.159825 0.048029 3.328 0.001
L1.Salzburg 0.034974 0.024365 1.435 0.151
L1.Steiermark 0.027295 0.031572 0.865 0.387
L1.Tirol 0.075297 0.025394 2.965 0.003
L1.Vorarlberg 0.056888 0.022375 2.542 0.011
L1.Wien 0.103292 0.042750 2.416 0.016
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178999 0.041364 4.327 0.000
L1.Burgenland 0.042816 0.022064 1.941 0.052
L1.Kärnten -0.012015 0.011307 -1.063 0.288
L1.Niederösterreich 0.143648 0.045930 3.128 0.002
L1.Oberösterreich 0.338084 0.046632 7.250 0.000
L1.Salzburg 0.098407 0.023656 4.160 0.000
L1.Steiermark 0.110725 0.030654 3.612 0.000
L1.Tirol 0.084802 0.024656 3.439 0.001
L1.Vorarlberg 0.054719 0.021724 2.519 0.012
L1.Wien -0.039912 0.041507 -0.962 0.336
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182120 0.080113 2.273 0.023
L1.Burgenland -0.041984 0.042733 -0.982 0.326
L1.Kärnten -0.036030 0.021900 -1.645 0.100
L1.Niederösterreich 0.120594 0.088956 1.356 0.175
L1.Oberösterreich 0.176377 0.090317 1.953 0.051
L1.Salzburg 0.252924 0.045817 5.520 0.000
L1.Steiermark 0.076092 0.059371 1.282 0.200
L1.Tirol 0.130180 0.047753 2.726 0.006
L1.Vorarlberg 0.107463 0.042075 2.554 0.011
L1.Wien 0.036449 0.080391 0.453 0.650
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.073340 0.063394 1.157 0.247
L1.Burgenland 0.015790 0.033815 0.467 0.641
L1.Kärnten 0.050927 0.017329 2.939 0.003
L1.Niederösterreich 0.183817 0.070391 2.611 0.009
L1.Oberösterreich 0.341925 0.071468 4.784 0.000
L1.Salzburg 0.050285 0.036255 1.387 0.165
L1.Steiermark -0.009785 0.046980 -0.208 0.835
L1.Tirol 0.123994 0.037787 3.281 0.001
L1.Vorarlberg 0.057810 0.033294 1.736 0.083
L1.Wien 0.113323 0.063613 1.781 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184022 0.077116 2.386 0.017
L1.Burgenland 0.011339 0.041134 0.276 0.783
L1.Kärnten -0.060332 0.021080 -2.862 0.004
L1.Niederösterreich -0.118005 0.085628 -1.378 0.168
L1.Oberösterreich 0.221481 0.086938 2.548 0.011
L1.Salzburg 0.036766 0.044103 0.834 0.404
L1.Steiermark 0.268767 0.057150 4.703 0.000
L1.Tirol 0.489124 0.045966 10.641 0.000
L1.Vorarlberg 0.073249 0.040501 1.809 0.071
L1.Wien -0.102973 0.077383 -1.331 0.183
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136286 0.085316 1.597 0.110
L1.Burgenland -0.013260 0.045508 -0.291 0.771
L1.Kärnten 0.064006 0.023322 2.744 0.006
L1.Niederösterreich 0.174384 0.094733 1.841 0.066
L1.Oberösterreich -0.075451 0.096182 -0.784 0.433
L1.Salzburg 0.222352 0.048792 4.557 0.000
L1.Steiermark 0.134020 0.063227 2.120 0.034
L1.Tirol 0.051307 0.050854 1.009 0.313
L1.Vorarlberg 0.142548 0.044808 3.181 0.001
L1.Wien 0.167443 0.085611 1.956 0.050
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.463534 0.047052 9.852 0.000
L1.Burgenland -0.001400 0.025098 -0.056 0.956
L1.Kärnten -0.013079 0.012862 -1.017 0.309
L1.Niederösterreich 0.176155 0.052245 3.372 0.001
L1.Oberösterreich 0.263665 0.053045 4.971 0.000
L1.Salzburg 0.018342 0.026909 0.682 0.495
L1.Steiermark -0.012699 0.034870 -0.364 0.716
L1.Tirol 0.069038 0.028046 2.462 0.014
L1.Vorarlberg 0.056692 0.024711 2.294 0.022
L1.Wien -0.018163 0.047215 -0.385 0.700
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025983 0.088188 0.152399 0.136429 0.064911 0.079964 0.015177 0.207078
Kärnten 0.025983 1.000000 -0.037251 0.128449 0.047047 0.071616 0.457010 -0.082706 0.094279
Niederösterreich 0.088188 -0.037251 1.000000 0.275426 0.094674 0.256664 0.045762 0.142834 0.241873
Oberösterreich 0.152399 0.128449 0.275426 1.000000 0.186561 0.289278 0.160614 0.126908 0.172478
Salzburg 0.136429 0.047047 0.094674 0.186561 1.000000 0.121077 0.058109 0.109693 0.060398
Steiermark 0.064911 0.071616 0.256664 0.289278 0.121077 1.000000 0.133359 0.087125 0.005390
Tirol 0.079964 0.457010 0.045762 0.160614 0.058109 0.133359 1.000000 0.062646 0.128810
Vorarlberg 0.015177 -0.082706 0.142834 0.126908 0.109693 0.087125 0.062646 1.000000 -0.011057
Wien 0.207078 0.094279 0.241873 0.172478 0.060398 0.005390 0.128810 -0.011057 1.000000